package main

import "fmt"

func main() {
	var arr1 []int
	fmt.Printf("%T %v %d %d\n", arr1, arr1, len(arr1), cap(arr1))
	fmt.Println(arr1 == nil)
	fmt.Println("-----------------------------------------------")

	// 切片为引用类型
	var arr3 = []int{10, 20, 30, 40, 50, 1}
	fmt.Println(len(arr3), cap(arr3))
	fmt.Println("-----------------------------------------------")

	var arr4 = []int{1: 10, 2: 20}
	fmt.Println(len(arr4), cap(arr4))
	fmt.Println("-----------------------------------------------")

	//切片扩容
	arr1 = append(arr1, 1, 2, 3, 4)
	fmt.Printf("%T %v %d %d\n", arr1, arr1, len(arr1), cap(arr1))

	fmt.Println("-----------------------------------------------")
	for idx, val := range arr1 {
		fmt.Println(idx, val)
	}

	fmt.Println("-----------------------------------------------")
	var arr5 = [6]int{1, 2, 3, 4, 5, 6}
	arr6 := arr5[:]
	fmt.Printf("%T %v %d %d\n", arr6, arr6, len(arr6), cap(arr6))
	arr7 := arr5[1:4]
	fmt.Printf("%T %v %d %d\n", arr7, arr7, len(arr7), cap(arr7))
	arr8 := arr5[:4]
	fmt.Printf("%T %v %d %d\n", arr8, arr8, len(arr8), cap(arr8))
	arr9 := arr5[2:]
	fmt.Printf("%T %v %d %d\n", arr9, arr9, len(arr9), cap(arr9))
	fmt.Println("-----------------------------------------------")

	arr10 := arr3[2:3]
	fmt.Printf("%T %v %d %d\n", arr10, arr10, len(arr10), cap(arr10))
	fmt.Println("-----------------------------------------------")
}
